import request from "@/utils/request";
import { RoleForm, RolePageVO, RoleQuery } from "./type";

/**
 * 获取角色分页数据
 *
 * @param queryParams
 */
export function getRolePageApi(
  queryParams?: RoleQuery
): PageResult<RolePageVO> {
  return request({
    url: "/role/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取角色下拉数据
 *
 * @param queryParams
 */
export function getRoleOptionsApi(
  queryParams?: RoleQuery
): Result<OptionType[]> {
  return request({
    url: "/role/options",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取角色的菜单ID集合
 *
 * @param roleId
 */
export function getRoleMenuIdsApi(roleId: number): Result<number[]> {
  return request({
    url: "/role/" + roleId + "/menuIds",
    method: "get",
  });
}

/**
 * 分配菜单权限给角色
 *
 * @param roleId
 * @param data
 */
export function updateRoleMenuApi(
  roleId: number,
  data: number[]
): Result<void> {
  return request({
    url: "/role/" + roleId + "/menus",
    method: "put",
    data: data,
  });
}

/**
 * 获取角色详情
 *
 * @param id
 */
export function getRoleFormApi(id: number): Result<RoleForm> {
  return request({
    url: "/role/" + id + "/form",
    method: "get",
  });
}

/**
 * 添加角色
 *
 * @param data
 */
export function addRoleApi(data: RoleForm): Result<void> {
  return request({
    url: "/role",
    method: "post",
    data: data,
  });
}

/**
 * 更新角色
 *
 * @param id
 * @param data
 */
export function updateRoleApi(id: number, data: RoleForm): Result<void> {
  return request({
    url: "/role",
    method: "put",
    data: data,
  });
}

/**
 * 批量删除角色，多个以英文逗号(,)分割
 *
 * @param ids
 */
export function deleteRoleApi(ids: string): Result<void> {
  return request({
    url: "/role/" + ids,
    method: "delete",
  });
}
